import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:get/get.dart';

import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';

class ChartInfoRow extends StatelessWidget {
  const ChartInfoRow(
      {super.key,
      this.indexName,
      this.index,
      required this.advice,
      this.maxNum = 10,
      this.level});

  final String? indexName;
  final String? index;
  final int? level;
  final String advice;
  final int maxNum;

  @override
  Widget build(BuildContext context) {
    return indexName.noValue && advice.noValue
        ? Container()
        : Stack(
            children: [
              if (index.hasValue && indexName.hasValue)
                Positioned.fill(
                    child: Image.asset(Utils.getImgPath('ai_info_row.png'),
                        fit: BoxFit.fill))
              else
                Positioned.fill(
                    child: Image.asset(Utils.getImgPath('ai_info_row_1.png'),
                        fit: BoxFit.fill)),
              Row(children: [
                if (index.hasValue && indexName.hasValue)
                  Expanded(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        QsText(indexName ?? "", color: Colours.goldFFD8C2),
                        ShaderMask(
                          shaderCallback: (Rect bounds) => const LinearGradient(
                                  colors: [
                                Colours.goldFFF3DC,
                                Colours.goldFFD8C2
                              ],
                                  begin: Alignment.topCenter,
                                  end: Alignment.bottomCenter)
                              .createShader(bounds),
                          child: QsText(index ?? "",
                              fontSize: 28,
                              color: Colours.white,
                              fontFamily: "YouShe",
                              height: 1),
                        ),
                        if (level.hasValue)
                          RatingBar(
                              initialRating: level! / 2,
                              itemCount: 5,
                              itemSize: 16,
                              itemPadding:
                                  const EdgeInsets.symmetric(horizontal: 1),
                              ignoreGestures: true,
                              allowHalfRating: true,
                              unratedColor: Colours.grey99,
                              ratingWidget: RatingWidget(
                                  full: Image.asset(
                                      width: 16,
                                      Utils.getImgPath("ai_star_on.png")),
                                  half: Image.asset(
                                      width: 16,
                                      Utils.getImgPath("ai_star_half.png")),
                                  empty: Image.asset(
                                      width: 16,
                                      Utils.getImgPath("ai_star_off.png"))),
                              onRatingUpdate: (rating) => 0)
                      ],
                    ),
                  ),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      const QsText("建议", color: Colours.goldFFD8C2),
                      ShaderMask(
                        shaderCallback: (Rect bounds) => const LinearGradient(
                                colors: [
                              Colours.goldFFF3DC,
                              Colours.goldFFD8C2
                            ],
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter)
                            .createShader(bounds),
                        child: QsText(advice,
                            fontSize: 24,
                            color: Colours.white,
                            fontFamily: "YouShe",
                            height: index == 0 ? 1 : 1.17),
                      ),
                      ShaderMask(
                          shaderCallback: (Rect bounds) => const LinearGradient(
                                      colors: [
                                    Colours.goldFFF3DC,
                                    Colours.goldFFD8C2
                                  ],
                                      begin: Alignment.topCenter,
                                      end: Alignment.bottomCenter)
                                  .createShader(bounds),
                          child: const QsText("仅供参考", color: Colours.white))
                    ],
                  ),
                )
              ]).paddingSymmetric(vertical: 10),
            ],
          );
  }
}
